define(
    [ "PDUtilDir/util", "PDUtilDir/grid" , "PDUtilDir/slidebar"],
    function(Util, Grid, Slidebar) {
        function visitorSupportInit($scope, $compile){
            return new visitorSupport($scope, $compile);
        }
        function visitorSupport($scope, $compile){
            this.entity = {};
            this.cache = {
                orderStatusMap: new Map(),
                orderStatus: new Array()
            };
            this.bind = {};
            this.$scope = $scope;
            this.$compile = $compile;
        }
        visitorSupport.fn = visitorSupport.prototype;
        visitorSupport.fn.digest = function(){
            this.$scope.$digest();
        }
        visitorSupport.fn.run = function(id) {
            var _this = this;
            _this.entity.id = id;
            this.slidebars = Slidebar({
                size : 'lg',
                url : getServer()
                + "/static/app/finance/groupFinanceInfos/views/visitor.html",
                $scope: this.$scope,
                $compile: this.$compile,
                afterLoad : function($Panel) {
                    _this.initialization();
                }
            });
        };
        visitorSupport.fn.initialization = function(){
            this.baseInit();
        };
        visitorSupport.fn.baseInit = function() {
            var _this = this;
            $.ajax({
                url : getServer() + "/flea/hclv/getVisitorOrderStatus.htmls",
                success : function(data) {
                    _this.cache.orderStatus = data.data;
                    $.each(data.data, function (index, row) {
                        _this.cache.orderStatusMap.set(row.dictCode, row.dictName);
                    });

                    _this.grid = Grid({
                        id : "GroupFinanceForVisitorGirdDivId",
                        pageSize : 10,
                        index : true,
                        pagination : true,
                        cache : false,
                        layout : [ {
                            name : "供应商",
                            field : "supplierName",
                            sort : true
                        }, {
                            name : "组团社",
                            field : "storeName",
                            sort : true
                        }, {
                            name : "订单号",
                            field : "orderNo",
                            sort : true
                        }, {
                            name : "数量",
                            field : "quantity",
                            sort : true
                        }, {
                            name : "金额",
                            field : "totalAmount"
                        }, {
                            name : "产品名称",
                            field : "totalAmount"
                        }, {
                            name : "订单状态",
                            field : "status",
                            format:function(e){
                                return _this.cache.orderStatusMap.get(e.row.status);
                            }
                        } ],
                        toolbar : [  ],
                        data : {
                            type : 'URL',
                            value : getServer() + '/flea/hclv/visitor/order/findListByGroupId.htmls?model=' + _this.entity.id
                        },
                        queryParam: {
                            model: _this.cache.id
                        }
                    });
                }
            });
        };
        return visitorSupportInit;
    });